package lumis.portal.page;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.IndexColumn;

/**
 * Stores the values of a parameter of a {@link PageWebResource}.
 *
 * @version $Revision: 12881 $ $Date: 2011-05-03 09:36:38 -0300 (Tue, 03 May 2011) $
 * @since 5.0.0
 */
@Entity
@Table(name="lum_WebResPageParam")
@GenericGenerator(name="portal-guid", strategy="lumis.portal.dao.hibernate.GuidGenerator")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
class PageWebResourceParameter
{
	@Id @GeneratedValue(generator="portal-guid")
	private String id;
	private String name;
	
	@CollectionOfElements(fetch=FetchType.EAGER)
	@BatchSize(size=500)
	@JoinTable(name="lum_WebResPageParamValue", joinColumns=@JoinColumn(name="parameterId"))
	@Column(name="parameterValue", nullable=false)
	@IndexColumn(name="position", base=0)
	@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
	private List<String> values = new ArrayList<String>();
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="webResourceId")
	private PageWebResource pageWebResource;
	
	public String getId()
	{
		return id;
	}
	public PageWebResource getPageWebResource()
	{
		return pageWebResource;
	}
	public void setPageWebResource(PageWebResource pageWebResource)
	{
		this.pageWebResource = pageWebResource;
	}
	public String getName()
	{
		return name;
	}
	public void setName(String name)
	{
		this.name = name;
	}
	public List<String> getValues()
	{
		return values;
	}
	
	/**
	 * Returns a string representation for debug and logging purposes.
	 * @return string representation for debug and logging purposes.
	 * @since 5.0.0
	 */
	public String toString()
	{
		return getName() + "=" + getValues();
	}
}